<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>数组算法-其它</title>
</head>
<body>
<script>
console.log('----------------------some----------------------');
const arr01 = [5, 3, 9, 4, 8];
//只有有一个返回true,则外层的值为true
const res01 = arr01.some((item, index, arr) => {
	if(index == 2) {
		return true;// 不会中断后续的遍历
	}

	return false;
});
console.log('res01:', res01);
</script>
<script>
console.log('----------------------every----------------------');
const arr02 = [5, 3, 9, 4, 8];
// every,若遍历中只要有一个返回false,则外层的值就为false
const res02 = arr02.every((item, index, arr) => {
	if(index == 2) {
		return false;// 停止遍历
	}
	return true;//继续遍历
});
console.log('res02:', res02);//false
</script>
<script>
console.log('----------------------filter----------------------');
const arr03 = [5, 3, 9, 4, 8];
// 检测数值元素，并返回符合条件所有元素的数组
const res03 = arr03.filter((item, index, arr) => {
	return item > 5;
});
console.log('res03:', res03);//[9, 8]
</script>
<script>
console.log('----------------------find----------------------');
const arr04 = [{
	a: 1,
},{
	a: 22,
},{
	a: 10,
}];
const res04 = arr04.find((item, index, arr) => {
	return item.a == 10;
});
console.log('res04:', res04);//{a: 10}
</script>
<script>
console.log('----------------------find----------------------');
const arr05 = [{
	a: 1,
},{
	a: 22,
},{
	a: 10,
}];
const res05 = arr05.findIndex((item, index, arr) => {
	return item.a == 10;
});
console.log('res05:', res05);//2
</script>
</body>
</html>